home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_objc.idb / usr / freeware / bin / cvtimport.z / cvtimport
Encoding:
Text File  |  1999-07-16  |  1.6 KB  |  109 lines

  1. #!/bin/sh
  2. # convert import to include and // to /* comments */
  3. # $Id: cvtimport,v 1.1.1.1 1999/03/22 21:48:43 stes Exp $
  4.  
  5. AWK=awk
  6. S="/tmp/$$.import"
  7. S2="/tmp/$$.comments"
  8. T="/tmp/$$.file"
  9. trap 'rm -f $T $S $S2' 1 2 3 10 15
  10.  
  11. cat > $S << EOF
  12. BEGIN {
  13.   g = ARGV[1]
  14.   gsub(/ /,"",g)
  15.   gsub(/\//,"_",g)
  16.   gsub(/\./,"_",g)
  17.   gsub(/[+-]/,"_",g)
  18.   cvted = 0
  19. }
  20. /^#[ ]*import/ {
  21.   if (!cvted) {
  22.     cvted = 1
  23.     print ""
  24.     print "#ifndef _" g "_"
  25.     print ""
  26.   }
  27.   gsub(/import/,"include");
  28.   print
  29.   next
  30. }
  31. {
  32.   print
  33. }
  34. END {
  35.   if (cvted) {
  36.   print ""
  37.   print "#define _" g "_"
  38.   print "#endif"
  39.   print ""
  40.   }
  41. }
  42. EOF
  43.  
  44. cat > $S2 << EOF
  45. function iscmt(s)
  46. {
  47.   return match(s,/\/\//);
  48. }
  49.  
  50. function subcmt(s,f,b,m,a) # b,m,a are locals (important for gawk)
  51. {
  52.   if ((n = match(s,/\"[^\"]*\"/)) || (n = match(s,/\/\*.*\*\//))) {
  53.      b = substr(s,1,RSTART - 1);
  54.      m = substr(s,RSTART,RLENGTH);
  55.      a = substr(s,RSTART+RLENGTH);
  56.      if (iscmt(b)) return subcmt(b,m a f); else return b m subcmt(a,f); 
  57.   }
  58.  
  59.   if (n = iscmt(s)) {
  60.      b = substr(s,1,RSTART - 1);
  61.      a = substr(s,RSTART+RLENGTH);
  62.      return b "/*" a f " */"
  63.   }
  64.  
  65.   return s f;
  66. }
  67.  
  68. /\/\// {
  69.   print subcmt(\$0,"")
  70.   next
  71. }
  72. {
  73.   print
  74. }
  75. EOF
  76.  
  77. CVTCMT=1
  78.  
  79. case $# in
  80.   0) echo "Usage: cvtimport [-c] files";exit 0;;
  81. esac
  82.  
  83. while :
  84.   do
  85.   case $1 in
  86.     -c) shift;CVTCMT=0;;
  87.     -*) echo "Usage: cvtimport [-c] files";exit 0;;
  88.     *)  break;;
  89.   esac
  90. done
  91.  
  92. for file
  93.   do
  94.     cp $file "$file~"
  95.     if $AWK -f $S $file > $T; then
  96.       cp $T $file
  97.       case $CVTCMT in
  98.         1) if $AWK -f $S2 $file > $T; then
  99.         cp $T $file
  100.        fi
  101.        ;;
  102.     0) ;;
  103.       esac
  104.     fi
  105.   done
  106.  
  107. rm $T $S $S2
  108.  
  109.